package liecai_class.day06;

/**
 * 栅栏 CyclicBarrier
 */
public class Demo05 {
    private static int count = 0;
    public static void main(String[] args) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(2000);
                    synchronized (Demo05.class) {
                        System.out.println("亚瑟加载游戏完成..");
                        count++;
                        if(count<3){
                            Demo05.class.wait();
                        }else{
                            Demo05.class.notifyAll();
                        }
                        System.out.println("亚瑟开始游戏!");
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(3000);
                    synchronized (Demo05.class) {
                        System.out.println("安其拉加载游戏完成..");
                        count++;
                        if(count<3){
                            Demo05.class.wait();
                        }else{
                            Demo05.class.notifyAll();
                        }
                        System.out.println("安其拉开始游戏!");
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(5000);
                    synchronized (Demo05.class) {
                        System.out.println("花木兰加载游戏完成..");
                        count++;
                        if(count<3){
                            Demo05.class.wait();
                        }else{
                            Demo05.class.notifyAll();
                        }
                        System.out.println("花木兰始游戏!");
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}
